#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2011 BidiX (http://bidix.info)
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
#
'''
Created on 27 janv. 2012

@author: BidiX
'''

import sys, os
import optparse

import unittest

USAGE = """%prog SDK_PATH TEST_PATH
Run unit tests for App Engine apps.

SDK_PATH    Path to the SDK installation
TEST_PATH   Path to package containing test modules"""


def main(sdk_path, test_path):
	sys.path.insert(0, sdk_path)
	# config appengine
	from google.appengine.dist import use_library
	use_library('django', '1.2')
	os.environ['DJANGO_SETTINGS_MODULE'] = 'notewiki.ui.django_settings'
	import dev_appserver
	dev_appserver.fix_sys_path()
	# config notewikiapp
	sys.path.insert(0, '/Users/bruno/Dev/notewikiapp/notewikiapp')
	import config
	
	suite = unittest.loader.TestLoader().discover(test_path)
	unittest.TextTestRunner(verbosity=2).run(suite)

if __name__ == '__main__':
	parser = optparse.OptionParser(USAGE)
	options, args = parser.parse_args()
	if len(args) != 2:
		print 'Error: Exactly 2 arguments required.'
		parser.print_help()
		sys.exit(1)
	SDK_PATH = args[0]
	TEST_PATH = args[1]
	main(SDK_PATH, TEST_PATH)
